// pages/teachTools/teachTools.js
const app = getApp()
const httpUtils = require('../../utils/httpUtils.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    barInfo: null,
    page: 1,
    size: 20,
    showSearchResult:false,
    mData:[],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      barInfo: app.globalData.barInfo
    });
    this.getData();
  },
  getData: function () {
    let that = this
    wx.showLoading({
      title: '正在加载',
      mask: true
    })
    httpUtils.teachingAids({
      access_token: app.globalData.$TOKEN,
      ptype:2,
      page: that.data.page,
      size: that.data.size

    }).then((res) => {
      wx.hideLoading()

      wx.hideLoading()
      if (that.data.page == 1) {
        that.data.mData.push(...res.data.lists);
      } else {
        that.data.mData.push(...res.data.lists);
      }
      that.data.page = that.data.page + 1;
      that.setData({
        mData: that.data.mData,
        page: that.data.page
      });
      if (that.data.mData.length >= res.data.total) {
        that.setData({
          showSearchResult: false
        })
      } else {
        that.setData({
          showSearchResult: true
        })
      }
    })
  },
  teachingAids: function (e) {
    this.setData({
      page:1,
      orderlist: [],
      showSearchResult: false,
      total: null,
    })
    let that = this
    wx.showLoading({
      title: '正在加载',
      mask: true
    })
    httpUtils.teachingAids({
      access_token: app.globalData.$TOKEN,
      title:e,

    }).then((res) => {
      wx.hideLoading()
    
      that.setData({
        mData: res.data.lists,
        page: 1,
        showSearchResult: false
      });
      console.log("this.data.mData.length:"+this.data.mData.length)
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  confirmTap: function (e) {
    
    this.teachingAids(e.detail.text)
    console.log("eqqq:");
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
    /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.showSearchResult==true) {
      console.log("11onReachBottom"+this.data.showSearchResult+this.data.page)
      this.getData();
    }
  },
  lookdetail: function (e) {
    var currext = e.currentTarget.dataset['id'];
    console.log("currext:" + currext)
    //查看详情
    wx.navigateTo({
      url: '/pages/coreseDetail/coreseDetail?id=' + currext,
    })
  },
})